package com.xl.exercise;

import java.util.Random;
import java.util.Scanner;

public class Test4 {

    public static void main(String[] args) {
        //抢红包
        int[] moneys = {9, 666, 188, 520, 99999};
        getRedPack(moneys);
    }

    public static void getRedPack(int[] moneys) {
        //moneys = [9,666,188,520,99999]
        Scanner scanner = new Scanner(System.in);
        Random rand = new Random();
        //定义一个for循环，控制抽奖5次
        for (int i = 0; i < 5; i++) {
            //提示粉丝抽奖
            System.out.println("请你输入任意内容进行抽奖：");
            scanner.next();
            //定义一个随机数，范围为0-4
            while (true) {
                int index = rand.nextInt(moneys.length);
                int money = moneys[index];
                if (money != 0) {
                    System.out.println("恭喜你，抽到一个" + money + "元红包");
                    moneys[index] = 0;
                    break; //结束这次抽奖
                }
            }
        }
    }
}
